<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8">
    
    <title>NumPy C-API &mdash; NumPy v1.18 Manual</title>
    
    <link rel="stylesheet" type="text/css" href="../../_static/css/spc-bootstrap.css">
    <link rel="stylesheet" type="text/css" href="../../_static/css/spc-extend.css">
    <link rel="stylesheet" href="../../_static/scipy.css" type="text/css" >
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" >
    <link rel="stylesheet" href="../../_static/graphviz.css" type="text/css" >
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '1.18.1',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  false
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../_static/language_data.js"></script>
    <script type="text/javascript" src="../../_static/js/copybutton.js"></script>
    <link rel="author" title="About these documents" href="../../about.html" >
    <link rel="index" title="Index" href="../../genindex.html" >
    <link rel="search" title="Search" href="../../search.html" >
    <link rel="top" title="NumPy v1.18 Manual" href="../../index.html" >
    <link rel="up" title="NumPy Reference" href="../index.html" >
    <link rel="next" title="Python Types and C-Structures" href="types-and-structures.html" >
    <link rel="prev" title="NumPy Distutils - Users Guide" href="../distutils_guide.html" > 
  </head>
  <body>
<div class="container">
  <div class="top-scipy-org-logo-header" style="background-color: #a2bae8;">
    <a href="../../index.html">
      <img border=0 alt="NumPy" src="../../_static/numpy_logo.png"></a>
    </div>
  </div>
</div>


    <div class="container">
      <div class="main">
        
	<div class="row-fluid">
	  <div class="span12">
	    <div class="spc-navbar">
              
    <ul class="nav nav-pills pull-left">
        <li class="active"><a href="https://numpy.org/">NumPy.org</a></li>
        <li class="active"><a href="https://numpy.org/doc">Docs</a></li>
        
        <li class="active"><a href="../../index.html">NumPy v1.18 Manual</a></li>
        

          <li class="active"><a href="../index.html" accesskey="U">NumPy Reference</a></li> 
    </ul>
              
              
    <ul class="nav nav-pills pull-right">
      <li class="active">
        <a href="../../genindex.html" title="General Index"
           accesskey="I">index</a>
      </li>
      <li class="active">
        <a href="types-and-structures.html" title="Python Types and C-Structures"
           accesskey="N">next</a>
      </li>
      <li class="active">
        <a href="../distutils_guide.html" title="NumPy Distutils - Users Guide"
           accesskey="P">previous</a>
      </li>
    </ul>
              
	    </div>
	  </div>
	</div>
        

	<div class="row-fluid">
      <div class="spc-rightsidebar span3">
        <div class="sphinxsidebarwrapper">
  <h4>Previous topic</h4>
  <p class="topless"><a href="../distutils_guide.html"
                        title="previous chapter">NumPy Distutils - Users Guide</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="types-and-structures.html"
                        title="next chapter">Python Types and C-Structures</a></p>
<div id="searchbox" style="display: none" role="search">
  <h4>Quick search</h4>
    <div>
    <form class="search" action="../../search.html" method="get">
      <input type="text" style="width: inherit;" name="q" />
      <input type="submit" value="search" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
          <div class="span9">
            
        <div class="bodywrapper">
          <div class="body" id="spc-section-body">
            
  <div class="section" id="numpy-c-api">
<span id="c-api"></span><h1>NumPy C-API<a class="headerlink" href="#numpy-c-api" title="Permalink to this headline">¶</a></h1>
<div class="line-block">
<div class="line">Beware of the man who won’t be bothered with details.</div>
<div class="line">— <em>William Feather, Sr.</em></div>
</div>
<div class="line-block">
<div class="line">The truth is out there.</div>
<div class="line">— <em>Chris Carter, The X Files</em></div>
</div>
<p>NumPy provides a C-API to enable users to extend the system and get
access to the array object for use in other routines. The best way to
truly understand the C-API is to read the source code. If you are
unfamiliar with (C) source code, however, this can be a daunting
experience at first. Be assured that the task becomes easier with
practice, and you may be surprised at how simple the C-code can be to
understand. Even if you don’t think you can write C-code from scratch,
it is much easier to understand and modify already-written source code
then create it <em>de novo</em>.</p>
<p>Python extensions are especially straightforward to understand because
they all have a very similar structure. Admittedly, NumPy is not a
trivial extension to Python, and may take a little more snooping to
grasp. This is especially true because of the code-generation
techniques, which simplify maintenance of very similar code, but can
make the code a little less readable to beginners. Still, with a
little persistence, the code can be opened to your understanding. It
is my hope, that this guide to the C-API can assist in the process of
becoming familiar with the compiled-level work that can be done with
NumPy in order to squeeze that last bit of necessary speed out of your
code.</p>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="types-and-structures.html">Python Types and C-Structures</a><ul>
<li class="toctree-l2"><a class="reference internal" href="types-and-structures.html#new-python-types-defined">New Python Types Defined</a></li>
<li class="toctree-l2"><a class="reference internal" href="types-and-structures.html#other-c-structures">Other C-Structures</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="config.html">System configuration</a><ul>
<li class="toctree-l2"><a class="reference internal" href="config.html#data-type-sizes">Data type sizes</a></li>
<li class="toctree-l2"><a class="reference internal" href="config.html#platform-information">Platform information</a></li>
<li class="toctree-l2"><a class="reference internal" href="config.html#compiler-directives">Compiler directives</a></li>
<li class="toctree-l2"><a class="reference internal" href="config.html#interrupt-handling">Interrupt Handling</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="dtype.html">Data Type API</a><ul>
<li class="toctree-l2"><a class="reference internal" href="dtype.html#enumerated-types">Enumerated Types</a></li>
<li class="toctree-l2"><a class="reference internal" href="dtype.html#defines">Defines</a></li>
<li class="toctree-l2"><a class="reference internal" href="dtype.html#c-type-names">C-type names</a></li>
<li class="toctree-l2"><a class="reference internal" href="dtype.html#printf-formatting">Printf Formatting</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="array.html">Array API</a><ul>
<li class="toctree-l2"><a class="reference internal" href="array.html#array-structure-and-data-access">Array structure and data access</a></li>
<li class="toctree-l2"><a class="reference internal" href="array.html#creating-arrays">Creating arrays</a></li>
<li class="toctree-l2"><a class="reference internal" href="array.html#dealing-with-types">Dealing with types</a></li>
<li class="toctree-l2"><a class="reference internal" href="array.html#array-flags">Array flags</a></li>
<li class="toctree-l2"><a class="reference internal" href="array.html#array-method-alternative-api">Array method alternative API</a></li>
<li class="toctree-l2"><a class="reference internal" href="array.html#functions">Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="array.html#auxiliary-data-with-object-semantics">Auxiliary Data With Object Semantics</a></li>
<li class="toctree-l2"><a class="reference internal" href="array.html#array-iterators">Array Iterators</a></li>
<li class="toctree-l2"><a class="reference internal" href="array.html#broadcasting-multi-iterators">Broadcasting (multi-iterators)</a></li>
<li class="toctree-l2"><a class="reference internal" href="array.html#neighborhood-iterator">Neighborhood iterator</a></li>
<li class="toctree-l2"><a class="reference internal" href="array.html#array-scalars">Array Scalars</a></li>
<li class="toctree-l2"><a class="reference internal" href="array.html#data-type-descriptors">Data-type descriptors</a></li>
<li class="toctree-l2"><a class="reference internal" href="array.html#conversion-utilities">Conversion Utilities</a></li>
<li class="toctree-l2"><a class="reference internal" href="array.html#miscellaneous">Miscellaneous</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="iterator.html">Array Iterator API</a><ul>
<li class="toctree-l2"><a class="reference internal" href="iterator.html#array-iterator">Array Iterator</a></li>
<li class="toctree-l2"><a class="reference internal" href="iterator.html#simple-iteration-example">Simple Iteration Example</a></li>
<li class="toctree-l2"><a class="reference internal" href="iterator.html#simple-multi-iteration-example">Simple Multi-Iteration Example</a></li>
<li class="toctree-l2"><a class="reference internal" href="iterator.html#iterator-data-types">Iterator Data Types</a></li>
<li class="toctree-l2"><a class="reference internal" href="iterator.html#construction-and-destruction">Construction and Destruction</a></li>
<li class="toctree-l2"><a class="reference internal" href="iterator.html#functions-for-iteration">Functions For Iteration</a></li>
<li class="toctree-l2"><a class="reference internal" href="iterator.html#converting-from-previous-numpy-iterators">Converting from Previous NumPy Iterators</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="ufunc.html">UFunc API</a><ul>
<li class="toctree-l2"><a class="reference internal" href="ufunc.html#constants">Constants</a></li>
<li class="toctree-l2"><a class="reference internal" href="ufunc.html#macros">Macros</a></li>
<li class="toctree-l2"><a class="reference internal" href="ufunc.html#functions">Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="ufunc.html#generic-functions">Generic functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="ufunc.html#importing-the-api">Importing the API</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="generalized-ufuncs.html">Generalized Universal Function API</a><ul>
<li class="toctree-l2"><a class="reference internal" href="generalized-ufuncs.html#definitions">Definitions</a></li>
<li class="toctree-l2"><a class="reference internal" href="generalized-ufuncs.html#details-of-signature">Details of Signature</a></li>
<li class="toctree-l2"><a class="reference internal" href="generalized-ufuncs.html#c-api-for-implementing-elementary-functions">C-API for implementing Elementary Functions</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="coremath.html">NumPy core libraries</a><ul>
<li class="toctree-l2"><a class="reference internal" href="coremath.html#numpy-core-math-library">NumPy core math library</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="deprecations.html">C API Deprecations</a><ul>
<li class="toctree-l2"><a class="reference internal" href="deprecations.html#background">Background</a></li>
<li class="toctree-l2"><a class="reference internal" href="deprecations.html#deprecation-mechanism-npy-no-deprecated-api">Deprecation Mechanism NPY_NO_DEPRECATED_API</a></li>
</ul>
</li>
</ul>
</div>
</div>


          </div>
        </div>
          </div>
        </div>
      </div>
    </div>

    <div class="container container-navbar-bottom">
      <div class="spc-navbar">
        
      </div>
    </div>
    <div class="container">
    <div class="footer">
    <div class="row-fluid">
    <ul class="inline pull-left">
      <li>
        &copy; Copyright 2008-2019, The SciPy community.
      </li>
      <li>
      Last updated on Feb 20, 2020.
      </li>
      <li>
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 2.4.2.
      </li>
    </ul>
    </div>
    </div>
    </div>
  </body>
</html>